import pagination from '@/views/pagination'  //分页组件
import agentHttp from '@/utils/agentHttp.js'
import {debounce} from '@/utils/index.js' 
import Edit from  './edit.vue' ;
import {timestampToTime,formatTimer,initDataTime} from '@/utils/index.js'


export default {
  name: 'priceAudit',
  created(){
     this.seachData(this.searchForm);
     this.getStatusMap();
  },
  components:{pagination,Edit},
  data() {
  	return {
      //搜索字段
  		searchForm:{
  			    dealerName:"",
            orderNumber:"",
            startDate:"",
            endDate:"",
            cashDepositStatus:'',   //保证金状态
            carOrderStatus:'',
  		},
      //表格字段
      tableData: [],
      carOrderStatus:'',    //库融状态
      cashDepositStatus:'', //保证金状态
      id:null,
      formLabelWidth:'120px',
      statusMap:'',
      //发送给弹窗的数据
      dialogSendData:{
        isAdd:true,                //是否为编辑或者新增  true是   false否
        dialogFormVisible:false,   //弹窗是否显示        true是   false否
      },
      startDateOpt: {
        disabledDate(time) {
          return time.getTime() > Date.now() 
        }
      },
      endDateOpt:{
        disabledDate:(time)=>{
          return  time.getTime()< new Date(this.searchForm.startDate).getTime();
        }
      },
      resetFormStatus:false,
      
  	}
  },

  methods: {
    seachData(){
      if(!this.resetFormStatus){
        var params=initDataTime(this.searchForm)||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        agentHttp.get('adminApi/admin/mortgage_cash_deposit/list',params ).then((data)=>{
              this.tableData = data.data.tableData
              this.carOrderStatus =  data.data.carOrderStatusMap ;
              this.cashDepositStatus = data.data.cashDepositStatusMap ; 
              
              
        })
      }
    },
    debounceSeach(){
      this.tableData.page=1;
      debounce(this.seachData(this.searchForm),1000)
    },
    //重置
    resetSearchForm(formName){
      this.$refs[formName].resetFields();
      this.seachData()
    },
    /*表格操作按钮*/
    //查看
    handleSee(e){
      const value = e.target.innerText ;
      this.dialogSendData.dialogFormVisible=true;
      const id = e.currentTarget.dataset.id ;
      this.id = id ;
      if(value==='审核'){
        this.dialogSendData.isAdd = false
      }else{
        this.dialogSendData.isAdd = true        
      }
    },
    handleEdit(index, row){
      this.dialogSendData.isAdd=true;
      this.dialogSendData.id=row.id;
      this.dialogSendData.dialogFormVisible=true;
    },
    getStatusMap(){
      agentHttp.get('adminApi/admin/car_order_price/get_status_map' ).then((data)=>{
        this.statusMap = data.data;
      })  
    },
    getDate(time){
      return timestampToTime(time)
    }
   
  }
}